package com.bc004346.travelus;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.bc004346.travelus.Fragment.FlightDetailsFragment;
import com.bc004346.travelus.Model.Abstract.SingleFragmentActivity;
import com.bc004346.travelus.Model.Domain.Flight;
import com.bc004346.travelus.Utility.Utility;

import static com.bc004346.travelus.Fragment.FlightDetailsFragment.EXTRA_FLIGHT_ID;

/**
 * Created by Renats on 9/8/2014.
 * Activity that will show flight details such as PNR, OND, availability, etc
 */
public class FlightDetailsActivity extends SingleFragmentActivity {

    private FlightDetailsFragment mFragment;
    private Flight mFlight;
    private TextView mStatus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mStatus = (TextView) findViewById(R.id.activityFragmentStatusTextView);
    }

    @Override
    protected Fragment getFragment() {
        try {
            mFlight = (Flight) getIntent()
                    .getSerializableExtra(EXTRA_FLIGHT_ID);
            mFragment = FlightDetailsFragment.newInstance(mFlight);
        } catch (Exception e) {
            Utility.log(e.toString());
            mStatus.setText(e.getMessage());
        }
        return mFragment;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_item_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        try {

            switch (item.getItemId()) {
                case R.id.menuRefresh:
                    mFragment.updateFlightDetails(mFlight);
                    break;
            }
        } catch (Exception e) {
            Utility.log(e.toString());
            mStatus.setText(e.getMessage());
        }

        return true;
    }
}
